package com.ls.pattern.composite.simpletree;

import java.util.ArrayList;
import java.util.List;

/**
 * 部门类
 *
 * @author 挥之以墨
 */
public class Dept extends BaseDept {

    private List<BaseDept> depts;
    private Integer level;

    public Dept(String name, Integer level) {
        super(name);
        this.level = level;
        this.depts = new ArrayList<>();
    }

    @Override
    public void showName() {
        System.out.println(this.name);
        for (BaseDept dept : depts) {
            for (int i = 0; i < this.level; i++) {
                System.out.print("   ");
            }
            for (int i = 0; i < this.level; i++) {
                if (i == 0) {
                    System.out.print("+");
                }
                System.out.print("-");
            }
            dept.showName();
        }
    }

    public Dept addChild(BaseDept dept) {
        this.depts.add(dept);
        return this;
    }

    public boolean removeChild(BaseDept dept) {
        return this.depts.remove(dept);
    }
}
